<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="日期">
        <el-date-picker
          v-model="queryParams.accessDate"
          size="small"
          style="width: 140px"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="OriginalRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" prop="id" width="60"/>
      <el-table-column label="设备号" align="center" prop="deviceNo" :show-overflow-tooltip="true" />
      <el-table-column label="设备出入类型" align="center" prop="deviceAccessType" :formatter="accessTypeFormat" />
      <el-table-column label="学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
      <el-table-column label="班级" align="center" prop="className"  :show-overflow-tooltip="true"/>
      <el-table-column label="学生姓名" align="center" prop="studentName"  :show-overflow-tooltip="true"/>
      <el-table-column label="出/入时间(刷脸时间)" align="center" prop="accessDate" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="考勤状态" align="center" prop="attenceStatus" :show-overflow-tooltip="true" :formatter="attencestatusFormat" /> -->

     <el-table-column label="操作" align="center" width="100" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            circle type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['smartdor:originalrecord:remove']"
          />
        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>



<script>
  import { listOriginal,delOriginal} from "@/api/report/originalrecord";

  export default {
    name: "OriginalRecord",
    data(){
      return{
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        OriginalRecordList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 考勤状态
        attenceStatusOptions: [],
        // 设备出入类型
        deviceAccessTypeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          accessDate: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
     };
    },
    created() {
      this.getList();
      this.getDicts("attence_status").then(response => {
        this.attenceStatusOptions = response.data;
      });
      this.getDicts("device_access_type").then(response => {
        this.deviceAccessTypeOptions = response.data;
      });
    },
    methods: {
      //回填考勤状态
      attencestatusFormat(row, column) {
        return this.selectDictLabel(this.attenceStatusOptions, row.attenceStatus);
      },
      accessTypeFormat(row,column) {
        return this.selectDictLabel(this.deviceAccessTypeOptions, row.deviceAccessType);
      },
      /** 查询原始记录列表 */
      getList() {
        this.loading = true;
        listOriginal(this.queryParams).then(response => {
            this.OriginalRecordList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除原始记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOriginal(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      }
    }
  }
  </script>
